package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.ssy.lingxi.member.merchant.handler.converter.JpaJsonToAuthBOConverter;
import com.ssy.lingxi.member.merchant.handler.converter.JpaJsonToChannelAuthBOConverter;
import com.ssy.lingxi.member.merchant.handler.converter.JpaJsonToDataAuthBOConverter;
import com.ssy.lingxi.member.merchant.model.bo.AuthBO;
import com.ssy.lingxi.member.merchant.model.bo.ChannelAuthBO;
import com.ssy.lingxi.member.merchant.model.bo.DataAuthBO;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * 用户权限
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-13
 */
@Entity
@Table(schema = "public", name = "ms_mc_member_user_auth", indexes = {@Index(name="ms_mc_member_user_auth_user_id_idx", columnList = "user_id")})
public class MemberUserAuthDO implements Serializable {
    private static final long serialVersionUID = 3452900504472851328L;

    /**
     * 用户Id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="member_user_auth_seq")
    @SequenceGenerator(sequenceName="ms_mc_member_user_auth_seq", name="member_user_auth_seq",allocationSize = 1)
    private Long id;

    /**
     * 一对一双向关联用户
     */
    @JsonBackReference
    @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name="user_id", referencedColumnName="id")
    private MemberUserDO user;

    /**
     * 菜单权限
     */
    @Convert(converter = JpaJsonToAuthBOConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<AuthBO> auth;

    /**
     * 数据权限，如此字段为空或null，则表示用户不需要做数据权限
     */
    @Convert(converter = JpaJsonToDataAuthBOConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<DataAuthBO> dataAuth;

    /**
     * 渠道权限，如此字段为空或null，则表示用户不需要做渠道权限
     */
    @Convert(converter = JpaJsonToChannelAuthBOConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<ChannelAuthBO> channelAuth;

    /**
     * 一对多单向关联数据权限配置
     */
    @OneToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "member_user_id", referencedColumnName = "id")
    private Set<MemberUserChannelDO> channels;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public MemberUserDO getUser() {
        return user;
    }

    public void setUser(MemberUserDO user) {
        this.user = user;
    }

    public List<AuthBO> getAuth() {
        return auth;
    }

    public void setAuth(List<AuthBO> auth) {
        this.auth = auth;
    }

    public List<DataAuthBO> getDataAuth() {
        return dataAuth;
    }

    public void setDataAuth(List<DataAuthBO> dataAuth) {
        this.dataAuth = dataAuth;
    }

    public List<ChannelAuthBO> getChannelAuth() {
        return channelAuth;
    }

    public void setChannelAuth(List<ChannelAuthBO> channelAuth) {
        this.channelAuth = channelAuth;
    }

    public Set<MemberUserChannelDO> getChannels() {
        return channels;
    }

    public void setChannels(Set<MemberUserChannelDO> channels) {
        this.channels = channels;
    }
}
